/*
** my_putnbr_base.c for my_putnbr_base in /home/goupil_r//afs/Jour_06
** 
** Made by robin goupil
** Login   <goupil_r@epitech.net>
** 
** Started on  Mon Oct  8 16:35:44 2012 robin goupil
** Last update Sun Nov 18 10:33:20 2012 robin goupil
*/

void	my_get_rest_base(long u_nb, long size, char *base)
{
  int	i;
  char	result[32];
  int	base_length;

  i = 0;
  base_length = 0;
  while (base[base_length] != '\0')
    {
      base_length = base_length + 1;
    }
  while (u_nb / base_length > 0)
    {
      result[i] = base[u_nb % base_length];
      u_nb = (u_nb - (u_nb % base_length)) / base_length;
      i = i + 1;
    }
  result[i] = base[u_nb % base_length];
  while (i >= 0)
    {
      my_putchar(result[i]);
      i = i - 1;
    }
}

long    my_putnbr_unsigned_base(unsigned int nbr, char *base)
{
  long  size;
  long  sign;

  size = 1;
  sign = 1;
  while ((sign * nbr) / (size * 10) != 0)
    size = size * 10;
  my_get_rest_base(nbr * sign, size, base);
  return (nbr);
}

long    my_putnbr_base(int nbr, char *base)
{
  long  size;
  long  sign;

  size = 1;
  sign = 1;
  if (nbr < 0)
    {
      my_putchar('-');
      sign = (-1);
    }
  while ((sign * nbr) / (size * 10) != 0)
    size = size * 10;
  my_get_rest_base(nbr * sign, size, base);
  return (nbr);
}
